package com.situ.science.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.situ.science.mapper.ProjectMapper;
import com.situ.science.pojo.vo.ProjectExcelVo;
import com.situ.science.pojo.vo.ProjectVo;
import org.springframework.beans.BeanUtils;

public class ProjectExcelListener extends AnalysisEventListener<ProjectExcelVo> {
    private ProjectMapper projectMapper;
    public ProjectExcelListener(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }
    //一行一行读取excel中的内容，从第二行开始读取
    @Override
    public void invoke(ProjectExcelVo projectExcelVo, AnalysisContext analysisContext) {
        ProjectVo projectVo = new ProjectVo();
        BeanUtils.copyProperties(projectExcelVo, projectVo);
        //插入的数据避免和原有id冲突
        projectVo.setId(null);
        projectMapper.add(projectVo);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("ProjectExcelListener.doAfterAllAnalysed");
    }
}
